<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>Title</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.2.3/css/bootstrap.css" rel="stylesheet">
</head>
<body>
<form style="width: 70%;margin: 50px auto 10px auto" action="GetTableServlet" method="get">
    <div class="input-group mb-5">
        <select class="form-select" name="tableName">
            <option selected>请选择要查询表</option>
            <c:forEach items="${tableNames}" var="item">
                <option value="${item}">${item}</option>
            </c:forEach>
        </select>
        <button class="btn btn-outline-secondary" type="submit">查询</button>
        <a class="btn btn-primary" href="addTable.jsp">添加表</a>
    </div>
</form>
<div style="width: 70%;margin: 50px auto 10px auto" class="text-center font-weight-bold h2">${table.tabbleName}表
    <a style="float: right" href="ToAddServlet?tableName=${table.tabbleName}"><button  class="btn btn-primary">插入数据</button></a>
</div>
<div style="width: 70%;margin: 50px auto 10px auto" class="table-responsive">
    <table class="table table-bordered col-md-auto">
        <thead>
        <tr>
            <c:forEach items="${table.columnName}" var="columnName">
                <th>${columnName}</th>
                <input type="hidden" name="columnName" value="${column}"/>
            </c:forEach>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${table.data}" var="row">
            <tr>
                <form method="post">
                    <c:forEach items="${row}" var="column" varStatus="status">
                        <td>${column}</td>
                        <input type="hidden" name="row" value="${column}"/>
                    </c:forEach>
                    <td>
                        <div>
                            <input type="hidden" name="tablename" value="${table.tabbleName}">
                            <button type="submit" formaction="ToUpdateServlet" class="btn btn-warning">编辑</button>
                            <button type="submit" formaction="DeleteDataServlet" class="btn btn-danger">删除</button>
                        </div>
                    </td>
                </form>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
</body>

</html>
